package com.ryskoo.catering.productspec.repository;

import com.ryskoo.catering.productspec.domain.ProductSpecPO;
import com.ryskoo.framework.core.repository.BasicJPAImpl;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class ProductSpecJPAImpl extends BasicJPAImpl<ProductSpecPO> implements IProductSpecRepository {
    @Override
    public void deleteByMainUuid(String mainUuid) {
        String hql = "delete from ProductSpecPO where productUuid = :productUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUuid);
        query.executeUpdate();
    }

    @Override
    public List<ProductSpecPO> getSpecsByMainUuid(String mainUuid) {
        String hql = "from ProductSpecPO where productUuid = :productUuid";
        Query query = getH4Session().createQuery(hql);
        query.setString("productUuid",mainUuid);
        return query.list();
    }

    @Override
    public void deleteByMainUuids(List<String> mainUuids) {
        String hql = "delete from ProductSpecPO where productUuid in (:mainUuids)";
        Query query = getH4Session().createQuery(hql);
        query.setParameterList("mainUuids",mainUuids);
        query.executeUpdate();
    }
}
